home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 365_02 / opts.c < prev    next >
C/C++ Source or Header  |  1992-04-04  |  18KB  |  798 lines

  1. /* opts.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* This file contains the code that manages the run-time options -- The 
  12.  * values that can be modified via the "set" command.
  13.  */
  14.  
  15. #include "config.h"
  16. #include "vi.h"
  17. #include "ctype.h"
  18. #ifndef NULL
  19. #define NULL (char *)0
  20. #endif
  21. extern char    *getenv();
  22.  
  23. /* maximum width to permit for strings, including ="" */
  24. #define MAXWIDTH 20
  25.  
  26. /* These are the default values of all options */
  27. char    o_autoindent[1] =    {FALSE};
  28. char    o_autoprint[1] =    {TRUE};
  29. char    o_autotab[1] =        {TRUE};
  30. char    o_autowrite[1] =     {FALSE};
  31. char    o_columns[3] =        {80, 32, 255};
  32. char    o_directory[30] =    TMPDIR;
  33. char    o_edcompatible[1] =    {FALSE};
  34. char    o_equalprg[80] =    {"fmt"};
  35. char    o_errorbells[1] =    {TRUE};
  36. char    o_exrefresh[1] =    {TRUE};
  37. char    o_ignorecase[1] =    {FALSE};
  38. char    o_keytime[3] =        {2, 0, 50};
  39. char    o_keywordprg[80] =    {KEYWORDPRG};
  40. char    o_lines[3] =        {25, 2, 96};
  41. char    o_list[1] =        {FALSE};
  42. char    o_number[1] =        {FALSE};
  43. char    o_readonly[1] =        {FALSE};
  44. char    o_remap[1] =        {TRUE};
  45. char    o_report[3] =        {5, 1, 127};
  46. char    o_scroll[3] =        {12, 1, 127};
  47. char    o_shell[60] =        SHELL;
  48. char    o_shiftwidth[3] =    {8, 1, 255};
  49. char    o_sidescroll[3] =    {8, 1, 40};
  50. char    o_sync[1] =        {NEEDSYNC};
  51. char    o_tabstop[3] =        {8, 1, 40};
  52. char    o_term[30] =        "?";
  53. char    o_flash[1] =        {TRUE};
  54. char    o_warn[1] =        {TRUE};
  55. char    o_wrapscan[1] =        {TRUE};
  56.  
  57. #ifndef CRUNCH
  58. char    o_beautify[1] =        {FALSE};
  59. char    o_exrc[1] =        {FALSE};
  60. char    o_mesg[1] =        {TRUE};
  61. char    o_more[1] =        {TRUE};
  62. char    o_novice[1] =        {FALSE};
  63. char    o_prompt[1] =        {TRUE};
  64. char    o_taglength[3] =    {0, 0, 30};
  65. char    o_terse[1] =        {FALSE};
  66. char    o_window[3] =        {0, 1, 24};
  67. char    o_wrapmargin[3] =    {0, 0, 255};
  68. char    o_writeany[1] =        {FALSE};
  69. #endif
  70.  
  71. #ifndef NO_ERRLIST
  72. char    o_cc[30] =        {CC_COMMAND};
  73. char    o_make[30] =        {MAKE_COMMAND};
  74. #endif
  75.  
  76. #ifndef NO_CHARATTR
  77. char    o_charattr[1] =        {FALSE};
  78. #endif
  79.  
  80. #ifndef NO_DIGRAPH
  81. char    o_digraph[1] =        {FALSE};
  82. char    o_flipcase[80]
  83. # ifdef CS_IBMPC
  84.     = {"\207\200\201\232\202\220\204\216\206\217\221\222\224\231\244\245"}
  85. # endif
  86. # ifdef CS_LATIN1
  87.     /* initialized by initopts() */
  88. # endif
  89.     ;
  90. #endif
  91.  
  92. #ifndef NO_SENTENCE
  93. char    o_hideformat[1] =    {FALSE};
  94. #endif
  95.  
  96. #ifndef NO_EXTENSIONS
  97. char    o_inputmode[1] =    {FALSE};
  98. char    o_ruler[1] =        {FALSE};
  99. #endif
  100.  
  101. #ifndef NO_MAGIC
  102. char    o_magic[1] =        {TRUE};
  103. #endif
  104.  
  105. #ifndef NO_MODELINES
  106. char    o_modelines[1] =    {FALSE};
  107. #endif
  108.  
  109. #ifndef NO_SENTENCE
  110. char    o_paragraphs[30] =    "PPppIPLPQP";
  111. char    o_sections[30] =    "NHSHSSSEse";
  112. #endif
  113.  
  114. #if MSDOS
  115. char    o_pcbios[1] =        {TRUE};
  116. #endif
  117.  
  118. #ifndef NO_SHOWMATCH
  119. char    o_showmatch[1] =    {FALSE};
  120. #endif
  121.  
  122. #ifndef    NO_SHOWMODE
  123. char    o_smd[1] =        {FALSE};
  124. #endif
  125.  
  126.  
  127. /* The following describes the names & types of all options */
  128. #define BOOL    0
  129. #define    NUM    1
  130. #define    STR    2
  131. #define SET    0x01    /* this option has had its value altered */
  132. #define CANSET    0x02    /* this option can be set at any time */
  133. #define RCSET    0x06    /* this option can be set in a .exrc file only */
  134. #define NOSAVE    0x0a    /* this option should never be saved by mkexrc */
  135. #define WSET    0x20    /* is this the "window" size option? */
  136. #define MR    0x40    /* does this option affect the way text is displayed? */
  137. struct
  138. {
  139.     char    *name;    /* name of an option */
  140.     char    *nm;    /* short name of an option */
  141.     char    type;    /* type of an option */
  142.     char    flags;    /* boolean: has this option been set? */
  143.     char    *value;    /* value */
  144. }
  145.     opts[] =
  146. {
  147.     /* name            type    flags        value */
  148.     { "autoindent",    "ai",    BOOL,    CANSET,        o_autoindent    },
  149.     { "autoprint",    "ap",    BOOL,    CANSET,        o_autoprint    },
  150.     { "autotab",    "at",    BOOL,    CANSET,        o_autotab    },
  151.     { "autowrite",    "aw",    BOOL,    CANSET,        o_autowrite    },
  152. #ifndef CRUNCH
  153.     { "beautify",    "bf",    BOOL,    CANSET,        o_beautify    },
  154. #endif
  155. #ifndef NO_ERRLIST
  156.     { "cc",        "cc",    STR,    CANSET,        o_cc        },
  157. #endif
  158. #ifndef NO_CHARATTR
  159.     { "charattr",    "ca",    BOOL,    CANSET|MR,    o_charattr    },
  160. #endif
  161.     { "columns",    "co",    NUM,    SET|NOSAVE|MR,    o_columns    },
  162. #ifndef NO_DIGRAPH
  163.     { "digraph",    "dig",    BOOL,    CANSET,        o_digraph    },
  164. #endif
  165.     { "directory",    "dir",    STR,    RCSET,        o_directory    },
  166.     { "edcompatible","ed",    BOOL,    CANSET,        o_edcompatible    },
  167.     { "equalprg",    "ep",    STR,    CANSET,        o_equalprg    },
  168.     { "errorbells",    "eb",    BOOL,    CANSET,        o_errorbells    },
  169. #ifndef CRUNCH
  170.     { "exrc",    "exrc",    BOOL,    CANSET,        o_exrc        },
  171. #endif
  172.     { "exrefresh",    "er",    BOOL,    CANSET,        o_exrefresh    },
  173.     { "flash",    "vbell",BOOL,    CANSET,        o_flash        },
  174. #ifndef NO_DIGRAPH
  175.     { "flipcase",    "fc",    STR,    CANSET,        o_flipcase    },
  176. #endif
  177. #ifndef NO_SENTENCE
  178.     { "hideformat",    "hf",    BOOL,    CANSET|MR,    o_hideformat    },
  179. #endif
  180.     { "ignorecase",    "ic",    BOOL,    CANSET,        o_ignorecase    },
  181. #ifndef NO_EXTENSIONS
  182.     { "inputmode",    "im",    BOOL,    CANSET,        o_inputmode    },
  183. #endif
  184.     { "keytime",    "kt",    NUM,    CANSET,        o_keytime    },
  185.     { "keywordprg",    "kp",    STR,    CANSET,        o_keywordprg    },
  186.     { "lines",    "ls",    NUM,    SET|NOSAVE|MR,    o_lines        },
  187.     { "list",    "li",    BOOL,    CANSET|MR,    o_list        },
  188. #ifndef NO_MAGIC
  189.     { "magic",    "ma",    BOOL,    CANSET,        o_magic        },
  190. #endif
  191. #ifndef NO_ERRLIST
  192.     { "make",    "mk",    STR,    CANSET,        o_make        },
  193. #endif
  194. #ifndef CRUNCH
  195.     { "mesg",    "me",    BOOL,    CANSET,        o_mesg        },
  196. #endif
  197. #ifndef NO_MODELINES
  198.     { "modelines",    "ml",    BOOL,    CANSET,        o_modelines    },
  199. #endif
  200. #ifndef CRUNCH
  201.     { "more",    "mo",    BOOL,    CANSET,        o_more        },
  202.     { "novice",    "nov",    BOOL,    CANSET,        o_novice    },
  203. #endif
  204.     { "number",    "nu",    BOOL,    CANSET|MR,    o_number    },
  205. #ifndef NO_SENTENCE
  206.     { "paragraphs",    "para",    STR,    CANSET,        o_paragraphs    },
  207. #endif
  208. #if MSDOS
  209.     { "pcbios",    "pc",    BOOL,    SET|NOSAVE,    o_pcbios    },
  210. #endif
  211. #ifndef CRUNCH
  212.     { "prompt",    "pr",    BOOL,    CANSET,        o_prompt    },
  213. #endif
  214.     { "readonly",    "ro",    BOOL,    CANSET,        o_readonly    },
  215.     { "remap",    "remap",BOOL,    CANSET,        o_remap        },
  216.     { "report",    "re",    NUM,    CANSET,        o_report    },
  217. #ifndef NO_EXTENSIONS
  218.     { "ruler",    "ru",    BOOL,    CANSET,        o_ruler        },
  219. #endif
  220.     { "scroll",    "sc",    NUM,    CANSET,        o_scroll    },
  221. #ifndef NO_SENTENCE
  222.     { "sections",    "sect",    STR,    CANSET,        o_sections    },
  223. #endif
  224.     { "shell",    "sh",    STR,    CANSET,        o_shell        },
  225. #ifndef NO_SHOWMATCH
  226.     { "showmatch",    "sm",    BOOL,    CANSET,        o_showmatch    },
  227. #endif
  228. #ifndef    NO_SHOWMODE
  229.     { "showmode",    "smd",    BOOL,    CANSET,        o_smd        },
  230. #endif
  231.     { "shiftwidth",    "sw",    NUM,    CANSET,        o_shiftwidth    },
  232.     { "sidescroll",    "ss",    NUM,    CANSET,        o_sidescroll    },
  233.     { "sync",    "sy",    BOOL,    CANSET,        o_sync        },
  234.     { "tabstop",    "ts",    NUM,    CANSET|MR,    o_tabstop    },
  235. #ifndef CRUNCH
  236.     { "taglength",    "tl",    NUM,    CANSET,        o_taglength    },
  237. #endif
  238.     { "term",    "te",    STR,    SET,        o_term        },
  239. #ifndef CRUNCH
  240.     { "terse",    "tr",    BOOL,    CANSET,        o_terse        },
  241.     { "timeout",    "to",    BOOL,    CANSET,        o_keytime    },
  242. #endif
  243. #ifndef CRUNCH
  244.     { "window",    "wi",    NUM,    CANSET|MR|WSET,    o_window    },
  245.     { "wrapmargin",    "wm",    NUM,    CANSET,        o_wrapmargin    },
  246. #endif
  247.     { "wrapscan",    "ws",    BOOL,    CANSET,        o_wrapscan    },
  248. #ifndef CRUNCH
  249.     { "writeany",    "wr",    BOOL,    CANSET,        o_writeany    },
  250. #endif
  251.     { NULL, NULL, 0, CANSET, NULL }
  252. };
  253.  
  254.  
  255. /* This function initializes certain options from environment variables, etc. */
  256. void initopts()
  257. {
  258.     char    *val;
  259.     int    i;
  260.  
  261.     /* set some stuff from environment variables */
  262. #if MSDOS
  263.     if (val = getenv("COMSPEC")) /* yes, ASSIGNMENT! */
  264. #else
  265.     if (val = getenv("SHELL")) /* yes, ASSIGNMENT! */
  266. #endif
  267.     {
  268.         strcpy(o_shell, val);
  269.     }
  270.  
  271.     strcpy(o_term, termtype);
  272. #if MSDOS
  273.     if (strcmp(termtype, "pcbios"))
  274.     {
  275.         o_pcbios[0] = FALSE;
  276.     }
  277.     else
  278.     {
  279.         o_pcbios[0] = TRUE;
  280.     }
  281. #endif
  282.  
  283. #if AMIGA || MSDOS || TOS
  284.     if ((val = getenv("TMP")) /* yes, ASSIGNMENT! */
  285.     ||  (val = getenv("TEMP")))
  286.         strcpy(o_directory, val);
  287. #endif
  288.  
  289. #ifndef CRUNCH
  290.     if ((val = getenv("LINES")) && atoi(val) > 4) /* yes, ASSIGNMENT! */
  291.     {
  292.         LINES = atoi(val);
  293.     }
  294.     if ((val = getenv("COLUMNS")) && atoi(val) > 30) /* yes, ASSIGNMENT! */
  295.     {
  296.         COLS = atoi(val);
  297.     }
  298. #endif
  299.     *o_lines = LINES;
  300.     *o_columns = COLS;
  301.     *o_scroll = LINES / 2 - 1;
  302. #ifndef CRUNCH
  303.     if (o_window[0] == 0)
  304.     {
  305.         o_window[0] = o_window[2] = *o_lines;
  306.     }
  307. #endif
  308.  
  309.     /* disable the flash option if we don't know how to do a flash */
  310.     if (!has_VB)
  311.     {
  312.         for (i = 0; opts[i].value != o_flash; i++)
  313.         {
  314.         }
  315.         opts[i].flags &